package com.lw.properties.migrator;

import com.lw.properties.migrator.config.MyProperties;
import com.lw.properties.migrator.config.MyProperties.App;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties.Servlet;
import org.springframework.context.ConfigurableApplicationContext;

@Slf4j
@SpringBootApplication
public class PropertiesMigratorApplication {

  public static void main(String[] args) {
    ConfigurableApplicationContext context =
        SpringApplication.run(PropertiesMigratorApplication.class, args);
    MyProperties myProperties = context.getBean(MyProperties.class);
    log.info("myProperties.name:{}", myProperties.getName());
    log.info(
        "myProperties$app.name:{}",
        Optional.ofNullable(myProperties.getApp()).orElse(new App()).getName());

    ServerProperties serverProperties = context.getBean(ServerProperties.class);
    log.info(
        "serverProperties$servlet.contextPath:{}",
        Optional.ofNullable(serverProperties.getServlet()).orElse(new Servlet()).getContextPath());
  }
}
